#include "SoundNode.h"
#include "assert.hpp"

SoundNode::SoundNode():m_pSound(0)
	,m_v3Vel(Ogre::Vector3::ZERO)
	,m_v3Pos(Ogre::Vector3::ZERO)
	,m_bLooping(false)
	,m_fSize(0.0f)
{
	setListener(&m_listener);
}
SoundNode::SoundNode(const Ogre::String& name,float size,bool looping ):Ogre::MovableObject(name)
	,m_pSound(0)
	,m_bLooping(looping)
	,m_v3Vel(Ogre::Vector3::ZERO)
	,m_v3Pos(Ogre::Vector3::ZERO)
	,m_fSize(size)
{
	setListener(&m_listener);
}

SoundNode::SoundNode(const Ogre::String& name,const Ogre::String& soundFile,float size,bool looping):Ogre::MovableObject(name)
	,m_strFileName(soundFile)
	,m_bLooping(looping)
	,m_fSize(size)
	,m_pSound(0)
{
	setListener(&m_listener);
}

SoundNode::~SoundNode(void)
{
}

void SoundNode::play(bool bLoop,bool bPaused)
{
	Ogre::Vector3 pos=Ogre::MovableObject::getParentSceneNode()->getPosition();

	m_pSound = SoundSystem::GetSingleton()->play3DSound(m_strFileName.c_str(),pos,m_v3Vel,m_fSize,bLoop,bPaused);
}

const Ogre::AxisAlignedBox& SoundNode::getBoundingBox(void)const
{
	return Ogre::AxisAlignedBox();
}

Ogre::Real SoundNode::getBoundingRadius(void)const
{
	return Ogre::Real(1.0f);
}

void SoundNode::SoundNodeListener::objectMoved(SoundNode* object)
{
}

void SoundNode::_update(float elapsedTime)
{
	Ogre::Vector3 pos=getParentSceneNode()->getPosition();

	fslSoundSetPosition(*m_pSound,pos.x,pos.y,pos.z);
}

void SoundNode::stop()
{
	fslSoundStop(*m_pSound);
}